import { createAlova } from 'alova';
import fetchAdapter from 'alova/fetch';
import vueHook from 'alova/vue';
import { createApis, withConfigType } from './createApis';

export const alovaInstance = createAlova({
  statesHook: vueHook,
  requestAdapter: fetchAdapter(),
  cacheFor: null,
  responded: {
    onSuccess: (res) => {
      const contentType = res.headers.get('Content-Type');
      if (contentType?.includes('text/event-stream')) {
        return res
      }
      return res.json();
    },
  }
});

export const $$userConfigMap = withConfigType({});

const Apis = createApis(alovaInstance, $$userConfigMap);

export default Apis;
